<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button onclick="getPersonInfo('1')">1</button>
<button onclick="getPersonInfo('2')">2</button>
<button onclick="getPersonInfo('T1')">T1</button>
</body>
<script>

    const readCardFuncMap = new Map();
    readCardFuncMap.set("T1", function (param) {
        return {
            type: "T1",
            name: param.name
        };
    });
    readCardFuncMap.set("1", function (param) {
        return {
            type: "1",
            name: param.name
        };
    });

    function readCardFuncFactory(cardType) {
        const readCardFunc = readCardFuncMap.get(cardType);
        if (typeof readCardFunc === "undefined" && readCardFunc === null) {
            throw new Error("无该读卡类型对应的读卡方法, 请先添加");
        }
        if (typeof readCardFunc !== "function") {
            throw new Error("该读卡类型获取到的函数并非函数类型, 实际为: " + typeof readCardFunc);
        }
        return readCardFunc;
    }

    function getPersonInfo(cardType) {
        let result = {
            state: 0,
            errorMessage: ""
        };

        let proc = new Promise((resolve, reject) => {
            let param = {
                "name": "qq1"
            };
            resolve(param);
        }).then((value) => {
            let readCardFunc = readCardFuncFactory(cardType);
            return Promise.resolve(readCardFunc(value));
        }, (reason) => {
            result.errorMessage = reason;
            return Promise.reject(reason)
        }).then((value) => {
            return Promise.resolve(callApi(value));
        }, (reason) => {
            result.errorMessage = reason;
            return Promise.reject(reason)
        }).then((value) => {
            return Promise.resolve(packageResult(value));
        }, (reason) => {
            result.errorMessage = reason;
            return Promise.reject(reason)
        }).then((value) => {
            result.state = 1;
            result.data = value;
            return Promise.resolve(result);
        });

        proc.then(value => {
            console.log(value);
        });
    }

    function callApi(value) {
        console.log("callApi invoke", value);
        return value;
    }

    function packageResult(value) {
        console.log("packageResult invoke", value);
        return value;
    }

</script>
</html>